home *** CD-ROM | disk | FTP | other *** search
- From: zodiac@darkness.gun.de (Ralph Seichter)
- Subject: SAS/C fopen("foo","a") -- is this a bug?
- Date: Wed, 31 Jan 96 17:51:42 CET
- Message-ID: <zpfaa8aCCygGZ1@da23.darkness.gun.de>
- X-ZC-PGP-KEY-AVAIL:
- Path: tim.xenologics.com!darkness.gun.de
- X-ZC-Telefon: V+49-2667-969000Q
- X-Newsreader: Zodiac's Point 37.207 [REGISTERED 0001] via Connectline-CLMSortin 2.25
- Newsgroups: comp.sys.amiga.programmer
- X-Gateway: ZConnect DA darkness.gun.de [Connectline/AmigaOS]
-
- I used the following test program:
-
- ----------8<----------8<----------8<----------8<----------8<----------
- /* test.c */
-
- #include <stdio.h>
-
- void main(void)
- {
- FILE *file;
-
- if (file = fopen("foo", "w"))
- {
- if (fprintf(file, "bar", 3) == 3)
- printf("write ok\n");
- fclose(file);
- }
-
- if (file = fopen("foo", "a"))
- {
- if (fprintf(file, "bar", 3) == 3)
- printf("append ok\n");
- fclose(file);
- }
- }
- ----------8<----------8<----------8<----------8<----------8<----------
-
- After I compiled this with SAS/C 6.56, I did the following in a shell:
-
- 1> sc link test.c
- 1> date >foo
- 1> protect foo r
- 1> test
- append ok
-
- The first fopen() with mode "w" fails, which is correct. But why can the
- write-protected file "foo" be opened with mode "a", and why won't fprintf()
- return an error? The file's contents are not changed, as is to be expected,
- but fprintf() reports that three bytes were written, which is not true.
-
- -Ralph
- --
- "Ja Ja!! Ich bin ein trottel !!!" (Nils G÷rs)
-